﻿function ShowAddOwnerForm(SetForWebPartId,PermissionTypeCode,RecordId)
{
    Url = Portal.SystemWebParts.SetPermission.SetPermission.GetShowSelectRoleAndUserUrl(SetForWebPartId, PermissionTypeCode, RecordId).value;
    window.open(Url, '_blank');
}


function ShowAddOwnerFormForOffice(SetForWebPartId, PermissionTypeCode, RecordId) {
    Url = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.GetShowSelectRoleAndUserUrl(SetForWebPartId, PermissionTypeCode, RecordId).value;
    window.open(Url, '_blank');
}


function ShowPermissionItemForm(RolePermissionId, SetForWebPartId, PermissionTypeCode, RecordId)
{
    Url = Portal.SystemWebParts.SetPermission.SetPermission.GetShowFormPermissionUrl(SetForWebPartId, RolePermissionId, PermissionTypeCode, RecordId).value;
    window.open(Url, '_blank');
}


function ShowPermissionItemFormForOffice(RolePermissionId, PermissionTypeCode, RecordId) {
    Url = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.GetShowFormPermissionUrl(RolePermissionId, PermissionTypeCode, RecordId).value;
    window.showModalDialog(Url, "", "dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;");
}

function JumpPageRole(SetForWebPartId, PermissionTypeCode, RecordId)
{
    document.getElementById("divProcessingText").innerHTML=Portal.SystemWebParts.SetPermission.AddToPermission.GetProcessingText().value;
    setTimeout("RealJumpPageRole('" + SetForWebPartId + "','" + PermissionTypeCode + "','" + RecordId + "')", 100);
}


function RealJumpPageRole(SetForWebPartId, PermissionTypeCode, RecordId)
{
    PageIndex=0;
    if(document.getElementById("divSelectPageRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectPageRole").selectedIndex;
    }
    Keyword=document.getElementById("txtKeyword").value;
    TypeIndex=document.getElementById("divSelectType").selectedIndex;
    retValue = Portal.SystemWebParts.SetPermission.AddToPermission.GetHtml(TypeIndex, SetForWebPartId, PermissionTypeCode, RecordId, Keyword, PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingText").innerHTML="";
    document.getElementById("divContentRole").innerHTML=retValue;
}



function JumpPageRoleForOffice(SetForWebPartId, PermissionTypeCode, RecordId) {
    document.getElementById("divProcessingText").innerHTML = Portal.SystemWebParts.SetPermission.AddToPermissionForOffice.GetProcessingText().value;
    setTimeout("RealJumpPageRoleForOffice('" + SetForWebPartId + "','" + PermissionTypeCode + "','" + RecordId + "')", 100);
}


function RealJumpPageRoleForOffice(SetForWebPartId, PermissionTypeCode, RecordId) {
    PageIndex = 0;
    if (document.getElementById("divSelectPageRole") != null) {
        PageIndex = document.getElementById("divSelectPageRole").selectedIndex;
    }
    Keyword = document.getElementById("txtKeyword").value;
    TypeIndex = document.getElementById("divSelectType").selectedIndex;
    retValue = Portal.SystemWebParts.SetPermission.AddToPermissionForOffice.GetHtml(TypeIndex, SetForWebPartId, PermissionTypeCode, RecordId, Keyword, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingText").innerHTML = "";
    document.getElementById("divContentRole").innerHTML = retValue;
}


function ClientAddItemFunc(SetForWebPartId,PermissionTypeCode, RecordId, Type, ItemId)
{
   document.getElementById("divProcessingText").innerHTML=Portal.SystemWebParts.SetPermission.AddToPermission.GetProcessingText().value;
   setTimeout("RealClientAddItemFunc('" + SetForWebPartId + "','" + PermissionTypeCode + "','" + RecordId + "','" + Type + "','" + ItemId + "')", 100);
}

function RealClientAddItemFunc(SetForWebPartId, PermissionTypeCode, RecordId, Type, ItemId)
{
    retValue = Portal.SystemWebParts.SetPermission.AddToPermission.ServerSideAddItem(SetForWebPartId, PermissionTypeCode, RecordId, Type, ItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }   
    document.getElementById("divProcessingText").innerHTML="";
    JumpPageRole(SetForWebPartId, PermissionTypeCode, RecordId);
}



function ClientAddItemFuncForOffice(WebPartId, PermissionTypeCode, RecordId, Type, ItemId) {
    document.getElementById("divProcessingText").innerHTML = Portal.SystemWebParts.SetPermission.AddToPermissionForOffice.GetProcessingText().value;
    setTimeout("RealClientAddItemFuncForOffice('" + WebPartId+"','"+ PermissionTypeCode + "','" + RecordId + "','" + Type + "','" + ItemId + "')", 100);
}

function RealClientAddItemFuncForOffice(SetForWebPartId, PermissionTypeCode, RecordId, Type, ItemId) {
    retValue = Portal.SystemWebParts.SetPermission.AddToPermissionForOffice.ServerSideAddItem(SetForWebPartId, PermissionTypeCode, RecordId, Type, ItemId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingText").innerHTML = "";
    JumpPageRoleForOffice(SetForWebPartId, PermissionTypeCode, RecordId);
}


function ClientRemoveItem(SetForWebPartId, RolePermissionId,PermissionTypeCode,RecordId)
{
    Msg=Portal.SystemWebParts.SetPermission.SetPermission.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    
    document.getElementById("divProcessingText").innerHTML=Portal.SystemWebParts.SetPermission.SetPermission.GetProcessingText().value;
    setTimeout("RealClientRemoveItem('" + SetForWebPartId+"','"+RolePermissionId + "','" + PermissionTypeCode + "','" + RecordId + "')", 100);
}

function RealClientRemoveItem(SetForWebPartId, RolePermissionId, PermissionTypeCode, RecordId)
{
    document.getElementById("divProcessingText").innerHTML="";
    retValue = Portal.SystemWebParts.SetPermission.SetPermission.ServerSideRemoveItem(RolePermissionId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    retValue = Portal.SystemWebParts.SetPermission.SetPermission.GetHtml(SetForWebPartId, PermissionTypeCode, RecordId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }   
    document.getElementById("divAssignRole").innerHTML=retValue;
}


function ClientRemoveItemForOffice(RolePermissionId, PermissionTypeCode, RecordId) {
    Msg = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;

    document.getElementById("divProcessingText").innerHTML = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.GetProcessingText().value;
    setTimeout("RealClientRemoveItemForOffice('" + RolePermissionId + "','" + PermissionTypeCode + "','" + RecordId + "')", 100);
}

function RealClientRemoveItemForOffice(RolePermissionId, PermissionTypeCode, RecordId) {
    document.getElementById("divProcessingText").innerHTML = "";
    retValue = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.ServerSideRemoveItem(RolePermissionId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    retValue = Portal.SystemWebParts.SetPermission.SetPermissionForOffice.GetHtml(PermissionTypeCode, RecordId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divAssignRole").innerHTML = retValue;
}

function SavePermissionItem(RolePermissionId,Max)
{
    for(var Index=0;Index<Max;Index++)
    {
        RolePermissionDetailId=document.getElementById("txtId_"+Index).value;
        checkedText=document.getElementById("checkBox_"+Index).checked;
        Portal.SystemWebParts.SetPermission.SetDetailPermission.SetPermissionItem(RolePermissionDetailId,checkedText).value;
    }
    alert(Portal.SystemWebParts.SetPermission.SetDetailPermission.GetSetOkMsg().value);
}

function CheckAll(Max)
{
    for(var Index=0;Index<Max;Index++)
    {
        document.getElementById("checkBox_"+Index).checked=true;
    }
}


function UnCheckAll(Max)
{
    for(var Index=0;Index<Max;Index++)
    {
        document.getElementById("checkBox_"+Index).checked=false;
    }
}

function InvertAll(Max)
{
    for(var Index=0;Index<Max;Index++)
    {
        document.getElementById("checkBox_"+Index).checked=!document.getElementById("checkBox_"+Index).checked;
    }
}


function ResetPermission(PermissionTypeCode,RecordId)
{
    document.getElementById("divProcessingText").innerHTML=Portal.SystemWebParts.SetPermission.SetDetailPermission.GetProcessingText().value;
    setTimeout("RealResetPermission('"+PermissionTypeCode+"','"+RecordId+"')",10);
}

function RealResetPermission(PermissionTypeCode,RecordId)
{
    retValue=Portal.SystemWebParts.SetPermission.SetDetailPermission.ResetPermission(PermissionTypeCode,RecordId).value;
    document.getElementById("divProcessingText").innerHTML="";
    alert(retValue);
}

function ClientDeleteFunction(FunctionCode) {
    ConfirmMsg=Portal.SystemWebParts.SetPermission.SetDetailPermission.GetConfirmDeleteMsg().value;
    if (confirm(ConfirmMsg) == false) return;
    retValue=Portal.SystemWebParts.SetPermission.SetDetailPermission.DeleteFunction(FunctionCode).value;
    alert(retValue);
}


function RefreshEffectObject(WebPartId,PermissionTypeCode, RecordId) {
    document.getElementById("divProcessingText").innerHTML = Portal.SystemWebParts.SetPermission.SetPermission.GetProcessingText().value;
    setTimeout("RealRefreshEffectObject('" + WebPartId+"','"+ PermissionTypeCode + "','" + RecordId + "')", 10);
}

function RealRefreshEffectObject(WebPartId, PermissionTypeCode, RecordId) {
    document.getElementById("divAssignRole").innerHTML = Portal.SystemWebParts.SetPermission.SetPermission.GetHtml(WebPartId, PermissionTypeCode, RecordId).value;
    document.getElementById("divProcessingText").innerHTML = "";
}

function ClientExtraPermission(RolePermissionId, ExtraPermissionId) {
    rValue = Portal.SystemWebParts.SetPermission.SetPermission.ServerSideDoExecuteExtraPermission(RolePermissionId, ExtraPermissionId).value;
    if (rValue.indexOf("ERROR") != -1) {
        alert(rValue);
        return;
    }
    window.open(rValue, '_blank');
}


function ClientExtraPermissionForDetail(RolePermissionId, RolePermissionDetailId, ExtraPermissionId) {
    rValue = Portal.SystemWebParts.SetPermission.SetDetailPermission.ServerSideDoExecuteExtraPermissionForDetail(RolePermissionId, RolePermissionDetailId, ExtraPermissionId).value;
    if (rValue.indexOf("ERROR") != -1) {
        alert(rValue);
        return;
    }
    window.open(rValue, '_blank');
}



function ClientReadingDetailPermission(PermissionTypeCode, RecordId, RolePermissionId) {
    document.getElementById("divProcessingText").innerHTML = Portal.SystemWebParts.SetPermission.SetDetailPermission.GetProcessingText().value;
    setTimeout("RealClientReadingDetailPermission('" + PermissionTypeCode + "','" + RecordId + "','"+RolePermissionId+"')", 10);
}


function RealClientReadingDetailPermission(PermissionTypeCode, RecordId, RolePermissionId) {
    document.getElementById("divRolePermissionDetail").innerHTML =
        Portal.SystemWebParts.SetPermission.SetDetailPermission.GetHtml(PermissionTypeCode, RecordId, RolePermissionId).value;
    document.getElementById("divProcessingText").innerHTML = "";
}